<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <input type="file" onchange="preview(this)" accept="image/jpeg">
  <img width="100" id="view">
  <script>
    function preview(file){
      var files  = file.files;
      //方法一：使用FileReader
      // var reader = new FileReader();
      // reader.onload = function(){
      //   view.src = this.result;
      // }
      // reader.readAsDataURL(files[0]);

      //方法二：使用createObjectURL 创建blob协议图片
      view.src = URL.createObjectURL(files[0])
    }
  </script>
</body>
</html>